/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.quality4spl.fm.cvm.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

import org.quality4spl.fm.cvm.ConfigDecisionFolder;
import org.quality4spl.fm.cvm.ConfigDecisionModel;
import org.quality4spl.fm.cvm.ConfigDecisionModelEntry;
import org.quality4spl.fm.cvm.CvmPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Config Decision Model Entry</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.quality4spl.fm.cvm.impl.ConfigDecisionModelEntryImpl#getParentModel <em>Parent Model</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.ConfigDecisionModelEntryImpl#getParentFolder <em>Parent Folder</em>}</li>
 *   <li>{@link org.quality4spl.fm.cvm.impl.ConfigDecisionModelEntryImpl#isActive <em>Active</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class ConfigDecisionModelEntryImpl extends ConfigDecisionModelElementImpl implements ConfigDecisionModelEntry {
	/**
	 * The default value of the '{@link #isActive() <em>Active</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isActive()
	 * @generated
	 * @ordered
	 */
	protected static final boolean ACTIVE_EDEFAULT = true;

	/**
	 * The cached value of the '{@link #isActive() <em>Active</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isActive()
	 * @generated
	 * @ordered
	 */
	protected boolean active = ACTIVE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ConfigDecisionModelEntryImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CvmPackage.Literals.CONFIG_DECISION_MODEL_ENTRY;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConfigDecisionModel getParentModel() {
		if (eContainerFeatureID() != CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL) return null;
		return (ConfigDecisionModel)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParentModel(ConfigDecisionModel newParentModel, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParentModel, CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentModel(ConfigDecisionModel newParentModel) {
		if (newParentModel != eInternalContainer() || (eContainerFeatureID() != CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL && newParentModel != null)) {
			if (EcoreUtil.isAncestor(this, newParentModel))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParentModel != null)
				msgs = ((InternalEObject)newParentModel).eInverseAdd(this, CvmPackage.CONFIG_DECISION_MODEL__ROOT_ENTRIES, ConfigDecisionModel.class, msgs);
			msgs = basicSetParentModel(newParentModel, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL, newParentModel, newParentModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ConfigDecisionFolder getParentFolder() {
		if (eContainerFeatureID() != CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER) return null;
		return (ConfigDecisionFolder)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParentFolder(ConfigDecisionFolder newParentFolder, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParentFolder, CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentFolder(ConfigDecisionFolder newParentFolder) {
		if (newParentFolder != eInternalContainer() || (eContainerFeatureID() != CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER && newParentFolder != null)) {
			if (EcoreUtil.isAncestor(this, newParentFolder))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParentFolder != null)
				msgs = ((InternalEObject)newParentFolder).eInverseAdd(this, CvmPackage.CONFIG_DECISION_FOLDER__CHILD_ENTRIES, ConfigDecisionFolder.class, msgs);
			msgs = basicSetParentFolder(newParentFolder, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER, newParentFolder, newParentFolder));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setActive(boolean newActive) {
		boolean oldActive = active;
		active = newActive;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, CvmPackage.CONFIG_DECISION_MODEL_ENTRY__ACTIVE, oldActive, active));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParentModel((ConfigDecisionModel)otherEnd, msgs);
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParentFolder((ConfigDecisionFolder)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				return basicSetParentModel(null, msgs);
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				return basicSetParentFolder(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				return eInternalContainer().eInverseRemove(this, CvmPackage.CONFIG_DECISION_MODEL__ROOT_ENTRIES, ConfigDecisionModel.class, msgs);
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				return eInternalContainer().eInverseRemove(this, CvmPackage.CONFIG_DECISION_FOLDER__CHILD_ENTRIES, ConfigDecisionFolder.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				return getParentModel();
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				return getParentFolder();
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__ACTIVE:
				return isActive();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				setParentModel((ConfigDecisionModel)newValue);
				return;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				setParentFolder((ConfigDecisionFolder)newValue);
				return;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__ACTIVE:
				setActive((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				setParentModel((ConfigDecisionModel)null);
				return;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				setParentFolder((ConfigDecisionFolder)null);
				return;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__ACTIVE:
				setActive(ACTIVE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_MODEL:
				return getParentModel() != null;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__PARENT_FOLDER:
				return getParentFolder() != null;
			case CvmPackage.CONFIG_DECISION_MODEL_ENTRY__ACTIVE:
				return active != ACTIVE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (active: ");
		result.append(active);
		result.append(')');
		return result.toString();
	}

} //ConfigDecisionModelEntryImpl
